/**
 * @filename:SysUploadConfigController 2022年1月27日
 * @project Wonder xhadmin Framework  V1.0
 * Copyright(c) 2020 LuZhongren Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.admin.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.wonder.admin.domain.SysUploadConfig;
import com.wonder.admin.service.SysUploadConfigService;
import com.wonder.admin.request.SysUploadConfigRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.utils.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**   
 * 
 * <p>说明： 上传参数配置API接口层</P>
 * @version: V1.0
 * @author: LuZhongren
 * @time    2022年1月27日
 *
 */
@Api(tags = "上传参数配置")
@RestController
@RequestMapping("/admin/Uploadconfig")
public class SysUploadConfigController {
	
	@Autowired
	private SysUploadConfigService sysUploadConfigService;
	
	@ApiOperation(value = "上传参数配置列表")
	@PostMapping("/index")
	public AjaxResult<CommonPage<SysUploadConfig>> index(@RequestBody SysUploadConfigRequest sysUploadConfigRequest) {
	
		Page<SysUploadConfig> page = new Page<SysUploadConfig>(sysUploadConfigRequest.getPage(), sysUploadConfigRequest.getLimit());
		IPage<SysUploadConfig> list = sysUploadConfigService.selectList(sysUploadConfigRequest, page);
		return AjaxResult.success(CommonPage.restPage(list));
	}
	
	/**
	 * @explain 查询对象  <swagger GET请求>
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getInfo")
	@ApiOperation(value = "获取上传参数配置对象", notes = "作者：LuZhongren")
	public AjaxResult<SysUploadConfig> getInfo(@RequestBody Map<String,Object> map){
	    if(map==null) AjaxResult.failed(MessageUtils.message("input.parameter.error"));
		Long id=Long.parseLong(map.get("id").toString());
	    
		SysUploadConfig sysUploadConfig=sysUploadConfigService.getById(id);
		if (null!=sysUploadConfig ) {
			 return AjaxResult.success(sysUploadConfig);
		}else {
			 return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		}
		
	}
	
	/**
	 * @explain 删除对象
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/delete")
	@ApiOperation(value = "删除", notes = "作者：LuZhongren")
	public AjaxResult<SysUploadConfig> delete(@RequestBody Map<String,Object> map){
		if(map==null)return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		String ids=map.get("id").toString();
		String[] deleteIds=StringUtils.split(ids, ',');
		List<Long> idList=new ArrayList<>(); 
		for(int i=0;i<deleteIds.length;i++)
		{
			idList.add( Long.parseLong(deleteIds[i]));//整数数组
		}

	    boolean rsg = sysUploadConfigService.removeBatchByIds(idList);
	    if (rsg) {
		    return AjaxResult.success(MessageUtils.message("delete.success"));
	    }else {
		   return AjaxResult.failed(MessageUtils.message("delete.fail"));
	    }
		
	}
	
	/**
	 * @explain 添加
	 * @param   对象参数：SysUploadConfig
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/add")
	@ApiOperation(value = "添加", notes = "作者：LuZhongren")
	public AjaxResult<SysUploadConfig> add(@RequestBody SysUploadConfig entity){

		if (null!=entity) {
			boolean rsg = sysUploadConfigService.save(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("insert.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("insert.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("insert.parameter.error"));
		}
	}
	
	/**
	 * @explain 修改
	 * @param   对象参数：SysUploadConfig
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "作者：LuZhongren")
	public AjaxResult<SysUploadConfig> update(@RequestBody SysUploadConfig entity){
		if (null!=entity) {
			boolean rsg = sysUploadConfigService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("update.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("update.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("update.not.exist"));
		}
	}
	
	
	/**
	 * @explain 查看对象明细  
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@PostMapping("/detail")
	@ApiOperation(value = "获取对象明细", notes = "作者：Wonder")
	public AjaxResult<SysUploadConfig> detail(@RequestBody Map<String,Object> map){
	    if(map==null) AjaxResult.failed(MessageUtils.message("input.parameter.error"));
	    Long id=Long.parseLong(map.get("id").toString());
	    
		SysUploadConfig entity=sysUploadConfigService.getById(id);
		if (null!=entity ) {
			 return AjaxResult.success(entity);
		}else {
			 return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		}
		
	}
	
	
	/**
	 * @explain 修改
	 * @param   对象参数：SysUploadConfig
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/updateExt")
	@ApiOperation(value = "修改", notes = "作者：LuZhongren")
	public AjaxResult<SysUploadConfig> updateExt(@RequestBody SysUploadConfig entity){
		if (null!=entity) {
			boolean rsg = sysUploadConfigService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("update.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("update.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("update.not.exist"));
		}
	}
	
	
}